#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n, q; cin >> n >> q;
	ll ans = 0;
	while (q--) {
		ll k; cin >> k;
		k--;
		if (n & (1ll << k)) continue; //1ll =((long long)1)
		ll c = n % (1ll << k);
		ans += (1ll << k) - c;
		n+= (1ll << k) - c;
	}
	cout << ans << endl;
	return 0;
}